﻿using System.Collections.Generic;
using Newtonsoft.Json.Linq;
using Kingdee.BOS;
using Kingdee.BOS.WebApi.Client;
using Kingdee.BOS.App.Data;
using System.Text;
using System;

namespace KingdeeWebServiceProject
{
    internal class K3BillBusinessHelper
    {
        #region 成本接口
        public string F_GetCostPrice(Context ctx, string strParams)
        {
            string result = "";
            string FieldKeys = "t1.FID,t6.FORGID,t5.FNUMBER,FPRICE";
            string FilterString = "";
            string Limit = "0";//最大行数，整型，不能超过2000（非必录）
            string StartRow = "0"; //开始行索引，整型（非必录）
            string TopRowCount = "0";//返回总行数，整型（非必录）
            string OrderString = "row_temp.FID";//排序字段

            JObject JstrParams = JObject.Parse(strParams);
            JObject Data = JObject.Parse(JstrParams["data"].ToString());

            try
            {
                if (Data.Property("FieldKeys") != null)
                {

                }

                if (Data.Property("FilterString") != null)
                {
                    FilterString = Data["FilterString"].ToString().ToUpper().Replace("FID", "t1.FID").Replace("FORGID", "t6.FORGID").Replace("FNUMBER", "t5.FNUMBER");
                }

                if (Data.Property("Limit") != null)
                {
                    Limit = Data["Limit"].ToString();
                }

                if (Data.Property("StartRow") != null)
                {
                    StartRow = Data["StartRow"].ToString();
                }

                if (Data.Property("TopRowCount") != null)
                {
                    TopRowCount = Data["TopRowCount"].ToString();
                }

                if (Data.Property("OrderString") != null)
                {
                    OrderString = Data["OrderString"].ToString().Replace("FID", "row_temp.FID").Replace("FORGID", "row_temp.FORGID").Replace("FNUMBER", "row_temp.FNUMBER");
                }

                if (Convert.ToInt32(TopRowCount) > 0L)
                {
                    if (Convert.ToInt32(TopRowCount) > 2000L)
                    {
                        TopRowCount = "2000";
                    }
                }
                else if (Convert.ToInt32(TopRowCount) == 0L)
                {
                    TopRowCount = "2000";
                }

            }
            catch (Exception)
            {
            }

            if (string.IsNullOrWhiteSpace(FieldKeys))
            {
                return "[[{\"Result\":{\"ResponseStatus\":{\"ErrorCode\":500,\"IsSuccess\":false,\"Errors\":[{\"FieldName\":null,\"Message\":\"data数据包中的参数FieldKeys的值不能为空。\",\"DIndex\":0}],\"SuccessEntitys\":[],\"SuccessMessages\":[],\"MsgCode\":0}}}]]";
            }
            try
            {
                //分页查询
                string Sql = string.Format(@"select top {4} row_temp.FID as FID,row_temp.FORGID as FORGID,row_temp.FNUMBER as FNUMBER,row_temp.FPRICE as FPRICE from (select row_number() over(order by A.FID asc) as rownumber,A.FID,A.FORGID,A.FNUMBER,
                case when (SUM(A.FQTY) + SUM(A.FCURRENTINQTY) - SUM(A.FOutStockQty)) <> 0 then ((SUM(A.FAMOUNT) + SUM(A.FCURRENTINAMOUNT) - SUM(A.FCURRENTOUTAMOUNT) )/(SUM(A.FQTY) + SUM(A.FCURRENTINQTY) - SUM(A.FOutStockQty))) else 0 end AS FPRICE
                from (select 
                t1.FID,
                T6.FORGID,
                t5.FNUMBER,
                case when t1.FEndInitKey = '0' then t1.FQTY else 0 end AS FQTY,
                case when t1.FEndInitKey = '0' then t1.FAMOUNT else 0 end AS FAMOUNT,
                case when t1.FEndInitKey = '1' then  t1.FCURRENTINQTY else 0 end AS FCURRENTINQTY,
                case when t1.FEndInitKey = '1' then  t1.FCURRENTINAMOUNT else 0 end AS FCURRENTINAMOUNT,
                CASE WHEN T1.FENDINITKEY = '1' then t1.FOutStockQty else 0 end as FOutStockQty,
                case when T1.FENDINITKEY = '1' then t1.FCURRENTOUTAMOUNT else 0 end as FCURRENTOUTAMOUNT
                from T_HS_BALANCE t1 
                inner join T_HS_OUTACCTG  t2 on t1.FID = t2.FID
                inner join T_HS_STOCKDIMENSION  t3 on t1.FDIMEENTRYID = t3.FENTRYID 
                inner join T_HS_CALDIMENSIONS t4 on t2.FDIMENSIONID = t4.FDIMENSIONID
                inner join T_BD_MATERIAL t5 on t5.FMATERIALID = t3.FMASTERID
                INNER JOIN T_ORG_ORGANIZATIONS t6 ON T4.FFINORGID = T6.FORGID
                where {1}
                ) A
                GROUP BY A.FID,A.FORGID,A.FNUMBER  ) row_temp where row_temp.rownumber > {3} ORDER BY {5}", FieldKeys, FilterString == "" ? "1=1" : FilterString, Limit, StartRow, TopRowCount, OrderString);
                var DynamicObjectCollection = DBUtils.ExecuteDynamicObject(ctx, Sql);
                if (DynamicObjectCollection != null && DynamicObjectCollection.Count > 0)
                {
                    if (DynamicObjectCollection.Count == 1)
                    {
                        StringBuilder sb = new StringBuilder();
                        sb.Append(DynamicObjectCollection[0]["FID"].ToString()).Append(",").Append(DynamicObjectCollection[0]["FORGID"].ToString()).Append(",").Append(DynamicObjectCollection[0]["FNUMBER"].ToString()).Append(",").Append(DynamicObjectCollection[0]["FPRICE"].ToString());
                        return "[" + sb.ToString() + "]";
                    }
                    else
                    {
                        for (int i = 0; i < DynamicObjectCollection.Count; i++)
                        {
                            StringBuilder sb = new StringBuilder();
                            sb.Append(DynamicObjectCollection[i]["FID"].ToString()).Append(",").Append(DynamicObjectCollection[i]["FORGID"].ToString()).Append(",").Append(DynamicObjectCollection[i]["FNUMBER"].ToString()).Append(",").Append(DynamicObjectCollection[i]["FPRICE"].ToString());
                            result += "[" + sb.ToString() + "],";
                        }
                    }
                }
                else
                {
                    return "[]";
                }
                return result = result.Remove(result.Length - 1, 1);
            }
            catch (System.Exception ex)
            {
                return "[[{\"Result\":{\"ResponseStatus\":{\"ErrorCode\":500,\"IsSuccess\":false,\"Errors\":[{\"FieldName\":null,\"Message\":\"查询处理出错：" + ex.ToString() + "，请联系管理员\",\"DIndex\":0}],\"SuccessEntitys\":[],\"SuccessMessages\":[],\"MsgCode\":0}}}]]";
            }
        }
        #endregion

        #region 查询物料分组
        public string F_QueryMatarilGroup(Context ctx, string strParams)
        {
            string result = "";
            string FieldKeys = "row_temp.FID, row_temp.FNUMBER,row_temp.FNAME,row_temp.FGROUPID,row_temp.FPARENTID,row_temp.FFULLPARENTID";
            string FilterString = "";
            string Limit = "0";//最大行数，整型，不能超过2000（非必录）
            string StartRow = "0"; //开始行索引，整型（非必录）
            string TopRowCount = "0";//返回总行数，整型（非必录）
            string OrderString = "row_temp.FID";//排序字段

            JObject JstrParams = JObject.Parse(strParams);
            JObject Data = JObject.Parse(JstrParams["data"].ToString());


            try
            {
                if (Data.Property("FieldKeys") != null)
                {
                    //FieldKeys = Data["FieldKeys"].ToString().ToUpper().Replace("FID", "row_temp.FID").Replace("FNUMBER", "row_temp.FNUMBER").Replace("FNAME", "row_temp.FNAME").Replace("FCROUPID", "row_temp.FGROUPID").Replace("FPARENTID", "row_temp.FPARENTID").Replace("FFULLPARENTID", "row_temp.FFULLPARENTID");
                }

                if (Data.Property("FilterString") != null)
                {
                    FilterString = Data["FilterString"].ToString().ToUpper().Replace("FID", "t1.FID").Replace("FNUMBER", "t1.FNUMBER").Replace("FNAME", "t2.FNAME").Replace("FCROUPID", "t1.FGROUPID").Replace("FPARENTID", "t1.FPARENTID").Replace("FFULLPARENTID", "t1.FFULLPARENTID");
                }

                if (Data.Property("Limit") != null)
                {
                    Limit = Data["Limit"].ToString();
                }

                if (Data.Property("StartRow") != null)
                {
                    StartRow = Data["StartRow"].ToString();
                }

                if (Data.Property("TopRowCount") != null)
                {
                    TopRowCount = Data["TopRowCount"].ToString();
                }

                if (Data.Property("OrderString") != null)
                {
                    OrderString = Data["OrderString"].ToString().Replace("FID", "row_temp.FID").Replace("FNUMBER", "row_temp.FNUMBER").Replace("FNAME", "row_temp.FNAME");
                }

                if (Convert.ToInt32(TopRowCount) > 0L)
                {
                    if (Convert.ToInt32(TopRowCount) > 2000L)
                    {
                        TopRowCount = "2000";
                    }
                }
                else if (Convert.ToInt32(TopRowCount) == 0L)
                {
                    TopRowCount = "2000";
                }

            }
            catch (Exception)
            {
            }

            if (string.IsNullOrWhiteSpace(FieldKeys))
            {
                return "[[{\"Result\":{\"ResponseStatus\":{\"ErrorCode\":500,\"IsSuccess\":false,\"Errors\":[{\"FieldName\":null,\"Message\":\"data数据包中的参数FieldKeys的值不能为空。\",\"DIndex\":0}],\"SuccessEntitys\":[],\"SuccessMessages\":[],\"MsgCode\":0}}}]]";
            }

            try
            {
                string Sql = string.Format(@"select top {4} {0} from
                (select row_number() over(order by t1.FID asc) as rownumber,t1.FID,t1.FNUMBER,t2.FNAME,T1.FGROUPID,t1.FPARENTID,
                T1.FFULLPARENTID from T_BD_MATERIALGROUP t1
                inner join T_BD_MATERIALGROUP_L t2 on  t2.FID = t1.FID where {1} ) row_temp where row_temp.rownumber > {3} order by {5} ", FieldKeys, FilterString == "" ? "1=1" : FilterString, Limit, StartRow, TopRowCount, OrderString == "" ? "row_temp.FID" : OrderString);
                var DynamicObjectCollection = DBUtils.ExecuteDynamicObject(ctx, Sql);
                if (DynamicObjectCollection != null && DynamicObjectCollection.Count > 0)
                {
                    if (DynamicObjectCollection.Count == 1)
                    {
                        StringBuilder sb = new StringBuilder();
                        sb.Append(DynamicObjectCollection[0]["FID"].ToString()).Append(",").Append(DynamicObjectCollection[0]["FNUMBER"].ToString()).Append(",").Append(DynamicObjectCollection[0]["FNAME"].ToString()).Append(",").Append(DynamicObjectCollection[0]["FGROUPID"].ToString()).Append(",").Append(DynamicObjectCollection[0]["FPARENTID"].ToString()).Append(",").Append(DynamicObjectCollection[0]["FFULLPARENTID"].ToString());
                        return "[" + sb.ToString() + "]";
                    }
                    else
                    {
                        for (int i = 0; i < DynamicObjectCollection.Count; i++)
                        {
                            StringBuilder sb = new StringBuilder();
                            sb.Append(DynamicObjectCollection[i]["FID"].ToString()).Append(",").Append(DynamicObjectCollection[i]["FNUMBER"].ToString()).Append(",").Append(DynamicObjectCollection[i]["FNAME"].ToString()).Append(",").Append(DynamicObjectCollection[i]["FGROUPID"].ToString()).Append(",").Append(DynamicObjectCollection[i]["FPARENTID"].ToString()).Append(",").Append(DynamicObjectCollection[i]["FFULLPARENTID"].ToString());
                            result += "[" + sb.ToString() + "],";
                        }
                    }
                }
                else
                {
                    return "[]";
                }
                return result = result.Remove(result.Length - 1, 1);
            }
            catch (System.Exception ex)
            {
                return "[[{\"Result\":{\"ResponseStatus\":{\"ErrorCode\":500,\"IsSuccess\":false,\"Errors\":[{\"FieldName\":null,\"Message\":\"处理出错：" + ex.ToString() + "，请联系管理员\",\"DIndex\":0}],\"SuccessEntitys\":[],\"SuccessMessages\":[],\"MsgCode\":0}}}]]";
            }
        }
        #endregion

        #region 查询客户物料
        public string F_QueryCustomerGroup(Context ctx, string strParams)
        {
            string result = "";
            string FieldKeys = "t1.FID as FID,t1.FNUMBER as FNUMBER,t2.FNAME as FNAME,t1.FGROUPID as FGROUPID";
            string FilterString = "";
            string Limit = "";
            JObject JstrParams = JObject.Parse(strParams);
            JObject Data = JObject.Parse(JstrParams["data"].ToString());
            //FieldKeys = Data["FieldKeys"].ToString();
            if (Data["FilterString"].ToString() != null)
            {
                FilterString = Data["FilterString"].ToString().ToUpper();

            }
            if (Data["Limit"].ToString() != null)
            {
                Limit = Data["Limit"].ToString();
            }
            if (string.IsNullOrWhiteSpace(FieldKeys))
            {
                return "[[{\"Result\":{\"ResponseStatus\":{\"ErrorCode\":500,\"IsSuccess\":false,\"Errors\":[{\"FieldName\":null,\"Message\":\"data数据包中的参数FieldKeys的值不能为空。\",\"DIndex\":0}],\"SuccessEntitys\":[],\"SuccessMessages\":[],\"MsgCode\":0}}}]]";
            }
            try
            {
                //字段  物料分组编码FNUMBER  物料分组名称FNAME  物料分组id FGROUPID
                //if (FieldKeys.Contains("FNUMBER"))
                //{
                //    FieldKeys = FieldKeys.Replace("FNUMBER", "t1.FNUMBER");
                //}
                //else if (FieldKeys.Contains("FNAME"))
                //{
                //    FieldKeys = FieldKeys.Replace("FNAME", "t2.FNAME");
                //}
                //else if (FieldKeys.Contains("FGROUPID"))
                //{
                //    FieldKeys = FieldKeys.Replace("FGROUPID", "t1.FGROUPID");
                //}
                //FieldKeys = FieldKeys.Replace("FID", "t1.FID");
                //过滤条件
                if (FilterString.Contains("FNUMBER"))
                {
                    FilterString = FilterString.Replace("FNUMBER", "t1.FNUMBER");
                }
                FilterString = FilterString.Replace("FID", "t1.FID");

                string Sql = string.Format(@"select {2} {0} from T_BD_CUSTOMERGROUP t1
                                             inner join T_BD_CUSTOMERGROUP_L t2 on  t2.FID = t1.FID
                                             where {1}", FieldKeys, FilterString == "" ? "1=1" : FilterString, Limit == "" ? "" : "top " + Limit + "");
                var DynamicObjectCollection = DBUtils.ExecuteDynamicObject(ctx, Sql);
                if (DynamicObjectCollection != null && DynamicObjectCollection.Count > 0)
                {
                    if (DynamicObjectCollection.Count == 1)
                    {
                        StringBuilder sb = new StringBuilder();
                        sb.Append(DynamicObjectCollection[0]["FID"].ToString()).Append(",").Append(DynamicObjectCollection[0]["FNUMBER"].ToString()).Append(",").Append(DynamicObjectCollection[0]["FNAME"].ToString()).Append(",").Append(DynamicObjectCollection[0]["FGROUPID"].ToString());
                        return "[" + sb.ToString() + "]";
                    }
                    else
                    {
                        for (int i = 0; i < DynamicObjectCollection.Count; i++)
                        {
                            StringBuilder sb = new StringBuilder();
                            sb.Append(DynamicObjectCollection[i]["FID"].ToString()).Append(",").Append(DynamicObjectCollection[0]["FNUMBER"].ToString()).Append(",").Append(DynamicObjectCollection[i]["FNAME"].ToString()).Append(",").Append(DynamicObjectCollection[i]["FGROUPID"].ToString());
                            result += "[" + sb.ToString() + "],";
                        }
                    }
                }
                else
                {
                    return "[]";
                }
                return result = result.Remove(result.Length - 1, 1);
            }
            catch (System.Exception ex)
            {
                return "[[{\"Result\":{\"ResponseStatus\":{\"ErrorCode\":500,\"IsSuccess\":false,\"Errors\":[{\"FieldName\":null,\"Message\":\"处理出错，请联系管理员,错误信息："+ ex.Message + "\",\"DIndex\":0}],\"SuccessEntitys\":[],\"SuccessMessages\":[],\"MsgCode\":0}}}]]";
            }
        }
        #endregion

        #region 单据查询
        public string F_Query(string strParams)
        {
            string resultQuery = "";
            JObject JstrParams = JObject.Parse(strParams);
            List<List<object>> objList = new List<List<object>>();
            K3CloudApiClient client = new K3CloudApiClient("http://127.0.0.1/K3Cloud/");
            var loginResult = client.ValidateLogin(JstrParams["dataCenterID"].ToString(), JstrParams["userName"].ToString(), JstrParams["passWord"].ToString(), 2052);
            var resultType = JObject.Parse(loginResult)["LoginResultType"].Value<int>();
            //登录结果类型等于1，代表登录成功
            if (resultType == 1)
            {
                try
                {
                    //单据查询的结果，将数据返回
                    objList = client.ExecuteBillQuery(JstrParams["data"].ToString());
                    if (objList.Count == 0)
                    {
                        return "[]";
                    }
                    //解析整理
                    resultQuery = "[" + resultQuery;
                    foreach (var list in objList)
                    {
                        for (int i = 0; i < list.Count; i++)
                        {
                            try
                            {
                                resultQuery = resultQuery + list[i].ToString() + ",";
                            }
                            catch (System.Exception)
                            {
                                resultQuery = resultQuery + "null" + ",";
                                continue;
                            }
                        }
                        resultQuery = resultQuery.Remove(resultQuery.Length - 1, 1);
                        resultQuery = resultQuery + "],[";
                    }
                    resultQuery = resultQuery.Remove(resultQuery.Length - 2, 2);

                    return resultQuery;
                }
                catch (System.Exception ex)
                {
                    return "[[{\"Result\":{\"ResponseStatus\":{\"ErrorCode\":500,\"IsSuccess\":false,\"Errors\":[{\"FieldName\":null,\"Message\":\"处理出错，请联系管理员，错误信息："+ ex.Message + "\",\"DIndex\":0}],\"SuccessEntitys\":[],\"SuccessMessages\":[],\"MsgCode\":0}}}]]";
                }
            }
            else
            {
                return "[" + loginResult + "]";
            }
        }
        #endregion

        #region 单据保存
        public string F_Save(string strParams)
        {
            JObject JstrParams = JObject.Parse(strParams);
            string fnumber = "";
            K3CloudApiClient client = new K3CloudApiClient("http://127.0.0.1/K3Cloud/");
            var loginResult = client.ValidateLogin(JstrParams["dataCenterID"].ToString(), JstrParams["userName"].ToString(), JstrParams["passWord"].ToString(), 2052);
            var resultType = JObject.Parse(loginResult)["LoginResultType"].Value<int>();
            //登录结果类型等于1，代表登录成功
            if (resultType == 1)
            {
                try
                {
                    string saveres = client.Save(JstrParams["formid"].ToString(), JstrParams["data"].ToString());
                    JObject res = JObject.Parse(saveres);
                    JObject res1 = JObject.Parse(res["Result"].ToString());
                    JObject res2 = JObject.Parse(res1["ResponseStatus"].ToString());
                        if (!res2["SuccessEntitys"].ToString().Equals("[]"))
                        {
                            JArray content = JArray.Parse(res2["SuccessEntitys"].ToString());
                            foreach (JObject List in content)
                            {
                                fnumber = List["Number"].ToString();
                                string Submit = "{\"Numbers\":[\"编码\"]}";
                                Submit = Submit.Replace("编码", fnumber);
                                string sub = client.Submit(JstrParams["formid"].ToString(), Submit);
                                JObject st1 = JObject.Parse(sub);
                                JObject st2 = JObject.Parse(st1["Result"].ToString());
                                JObject st3 = JObject.Parse(st2["ResponseStatus"].ToString());
                                string aud = client.Audit(JstrParams["formid"].ToString(), Submit);
                                JObject st4 = JObject.Parse(aud);
                                JObject st5 = JObject.Parse(st4["Result"].ToString());
                                JObject st6 = JObject.Parse(st5["ResponseStatus"].ToString());
                            }
                        }
                    return res1.ToString();
                }
                catch (System.Exception ex)
                {
                    return "{\"Result\":{\"ResponseStatus\":{\"ErrorCode\":500,\"IsSuccess\":false,\"Errors\":[{\"FieldName\":null,\"Message\":\"" + ex.Message.ToString() + "\",\"DIndex\":0}],\"SuccessEntitys\":[],\"SuccessMessages\":[],\"MsgCode\":0}}}";
                }
            }
            else
            {
                return "[" + loginResult + "]";
            }
        }
        #endregion

        #region 单据提交
        public string F_Submit(string strParams)
        {
            JObject JstrParams = JObject.Parse(strParams);
            K3CloudApiClient client = new K3CloudApiClient("http://127.0.0.1/K3Cloud/");
            var loginResult = client.ValidateLogin(JstrParams["dataCenterID"].ToString(), JstrParams["userName"].ToString(), JstrParams["passWord"].ToString(), 2052);
            var resultType = JObject.Parse(loginResult)["LoginResultType"].Value<int>();
            //登录结果类型等于1，代表登录成功
            if (resultType == 1)
            {
                try
                {
                    return client.Submit(JstrParams["formid"].ToString(), JstrParams["data"].ToString());
                }
                catch (System.Exception ex)
                {
                    return "{\"Result\":{\"ResponseStatus\":{\"ErrorCode\":500,\"IsSuccess\":false,\"Errors\":[{\"FieldName\":null,\"Message\":\"" + ex.Message.ToString() + "\",\"DIndex\":0}],\"SuccessEntitys\":[],\"SuccessMessages\":[],\"MsgCode\":0}}}";
                }

            }
            else
            {
                return "[" + loginResult + "]";
            }
        }
        #endregion

        #region 单据审核
        public string F_Audit(string strParams)
        {
            JObject JstrParams = JObject.Parse(strParams);
            K3CloudApiClient client = new K3CloudApiClient("http://127.0.0.1/K3Cloud/");
            var loginResult = client.ValidateLogin(JstrParams["dataCenterID"].ToString(), JstrParams["userName"].ToString(), JstrParams["passWord"].ToString(), 2052);
            var resultType = JObject.Parse(loginResult)["LoginResultType"].Value<int>();
            //登录结果类型等于1，代表登录成功
            if (resultType == 1)
            {
                try
                {
                    return client.Audit(JstrParams["formid"].ToString(), JstrParams["data"].ToString());
                }
                catch (System.Exception ex)
                {
                    return "{\"Result\":{\"ResponseStatus\":{\"ErrorCode\":500,\"IsSuccess\":false,\"Errors\":[{\"FieldName\":null,\"Message\":\"" + ex.Message.ToString() + "\",\"DIndex\":0}],\"SuccessEntitys\":[],\"SuccessMessages\":[],\"MsgCode\":0}}}";
                }

            }
            else
            {
                return "[" + loginResult + "]";
            }
        }
        #endregion

        #region 单据反审核
        public string F_UnAudit(string strParams)
        {
            JObject JstrParams = JObject.Parse(strParams);
            K3CloudApiClient client = new K3CloudApiClient("http://127.0.0.1/K3Cloud/");
            var loginResult = client.ValidateLogin(JstrParams["dataCenterID"].ToString(), JstrParams["userName"].ToString(), JstrParams["passWord"].ToString(), 2052);
            var resultType = JObject.Parse(loginResult)["LoginResultType"].Value<int>();
            //登录结果类型等于1，代表登录成功
            if (resultType == 1)
            {
                try
                {
                    return client.UnAudit(JstrParams["formid"].ToString(), JstrParams["data"].ToString());
                }
                catch (System.Exception ex)
                {
                    return "{\"Result\":{\"ResponseStatus\":{\"ErrorCode\":500,\"IsSuccess\":false,\"Errors\":[{\"FieldName\":null,\"Message\":\"" + ex.Message.ToString() + "\",\"DIndex\":0}],\"SuccessEntitys\":[],\"SuccessMessages\":[],\"MsgCode\":0}}}";
                }

            }
            else
            {
                return "[" + loginResult + "]";
            }
        }
        #endregion

        #region 单据下推
        public string F_Push(string strParams)
        {
            JObject JstrParams = JObject.Parse(strParams);
            K3CloudApiClient client = new K3CloudApiClient("http://127.0.0.1/K3Cloud/");
            var loginResult = client.ValidateLogin(JstrParams["dataCenterID"].ToString(), JstrParams["userName"].ToString(), JstrParams["passWord"].ToString(), 2052);
            var resultType = JObject.Parse(loginResult)["LoginResultType"].Value<int>();
            //登录结果类型等于1，代表登录成功
            if (resultType == 1)
            {
                try
                {
                    return client.Push(JstrParams["formid"].ToString(), JstrParams["data"].ToString());
                }
                catch (System.Exception ex)
                {
                    return "{\"Result\":{\"ResponseStatus\":{\"ErrorCode\":500,\"IsSuccess\":false,\"Errors\":[{\"FieldName\":null,\"Message\":\"" + ex.Message.ToString() + "\",\"DIndex\":0}],\"SuccessEntitys\":[],\"SuccessMessages\":[],\"MsgCode\":0}}}";
                }

            }
            else
            {
                return "[" + loginResult + "]";
            }
        }
        #endregion

        #region 单据删除
        public string F_Delete(string strParams)
        {
            JObject JstrParams = JObject.Parse(strParams);
            K3CloudApiClient client = new K3CloudApiClient("http://127.0.0.1/K3Cloud/");
            var loginResult = client.ValidateLogin(JstrParams["dataCenterID"].ToString(), JstrParams["userName"].ToString(), JstrParams["passWord"].ToString(), 2052);
            var resultType = JObject.Parse(loginResult)["LoginResultType"].Value<int>();
            //登录结果类型等于1，代表登录成功
            if (resultType == 1)
            {
                try
                {
                    return client.Delete(JstrParams["formid"].ToString(), JstrParams["data"].ToString());
                }
                catch (System.Exception ex)
                {
                    return "{\"Result\":{\"ResponseStatus\":{\"ErrorCode\":500,\"IsSuccess\":false,\"Errors\":[{\"FieldName\":null,\"Message\":\"" + ex.Message.ToString() + "\",\"DIndex\":0}],\"SuccessEntitys\":[],\"SuccessMessages\":[],\"MsgCode\":0}}}";
                }

            }
            else
            {
                return "[" + loginResult + "]";
            }
        }
        #endregion
    }
}
